package com.sky.demo.service.impl;

import java.util.List;
import java.util.Map;

import org.realogic.btp.sequence.KSequenceGenerator;
import org.realogic.cfm.domain.KPageResult;
import org.realogic.cfm.persistence.query.QueryCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;
import com.sky.demo.entity.EntityWarehouse;
import com.sky.demo.repository.EntityWarehouseDao;
import com.sky.demo.service.EntityWarehouseService;

/**
 * @see EntityWarehouseService
 */
@Service("entityWarehouseService")
public class EntityWarehouseServiceImpl implements EntityWarehouseService {

	// private Log log = LogFactory.getLog(getClass());

	private EntityWarehouseDao entityWarehouseDao;

	public EntityWarehouseServiceImpl() {

	}

	public EntityWarehouseDao getEntityWarehouseDao() {
		return entityWarehouseDao;
	}

	@Autowired
	public void setEntityWarehouseDao(EntityWarehouseDao entityWarehouseDao) {
		this.entityWarehouseDao = entityWarehouseDao;
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int create(final EntityWarehouse aModel) {
		if (aModel.getId() == null || aModel.getId() == 0l) {
			aModel.setId(KSequenceGenerator.uuidOfLang());
		}
		return entityWarehouseDao.create(aModel);
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int update(final EntityWarehouse aModel) {
		return entityWarehouseDao.update(aModel);
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int remove(final Long aKey) {
		return entityWarehouseDao.remove(aKey);
	}

	public EntityWarehouse read(final Long aKey) {
		return entityWarehouseDao.read(aKey);
	}

	public KPageResult query(QueryCondition aCondition) {
		List<EntityWarehouse> tmpList = entityWarehouseDao.query(aCondition);
		KPageResult temp = null;
		if (tmpList != null) {
			temp = new KPageResult(tmpList, aCondition.getTotalSize(), aCondition.getPageNo(), aCondition.getPageSize());
		}
		return temp;
	}

	public PageInfo<EntityWarehouse> query(Map<String, Object> aCondition, int aPageNo, int aPageSize) {
		return entityWarehouseDao.query(aCondition, aPageNo, aPageSize);
	}

	public List<EntityWarehouse> query(Map<String, Object> aCondition) {
		return entityWarehouseDao.query(aCondition);
	}

}